<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    // 网站首页
    public function index()
    {
        // 查询导航栏 nav
        $nav = Db::name('nav')->select();
        // 查询轮播图 banner
        $banner = Db::name('banner')->select();
        // 查询新闻公告 news
        $news1 = Db::name('news')
            ->order(['createtime'=>'desc','id'=>'desc'])
            ->find();
        $news2 = Db::name('news')
            ->order(['createtime'=>'desc','id'=>'desc'])
            ->limit(1, 3)
            ->select();

        // 教研动态
        $jydt1 = Db::name('news')
            ->order(['createtime'=>'desc','id'=>'desc'])
            ->find();
        $jydt2 = Db::name('news')
            ->order(['createtime'=>'desc','id'=>'desc'])
            ->select();

        // 社会服务
        $shfw = Db::name('news')
            ->order(['createtime'=>'desc','id'=>'desc'])
            ->find();

        // 主题活动
        $theme = Db::name('theme')
            ->limit('4')
            ->select();

        // 马院风采
        $fengcai = Db::name('fengcai')
            ->select();

        // 友情链接
        $link = Db::name('link')->select();

        $this->assign('nav', $nav);
        $this->assign('banner', $banner);
        $this->assign('news', $news1);
        $this->assign('news2', $news2);
        $this->assign('jydt1', $jydt1);
        $this->assign('jydt2', $jydt2);
        $this->assign('shfw', $shfw);
        $this->assign('theme', $theme);
        $this->assign('fc', $fengcai);
        $this->assign('link', $link);

        $this->assign('time', time());

        return $this->view->fetch();
    }

    // 查看某个文章的详情
    public function detail()
    {
        $id = input('id/d');
        if (empty($id)) {
            return '参数错误';
        }
        $news = Db::name('news')->find($id);
        $this->assign('article', $news);
        return $this->view->fetch('detail');
    }
}
